/*
JETware Hands-free Extension provides additional features for Windows Mobile HFP support.
Copyright (C) 2004-2009 Jim Thatcher

This program is free software; you can redistribute it and/or modify it under the terms of the 
GNU General Public License as published by the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; 
if not, write to the Free Software Foundation, Inc., 
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Defines Contact and supporting classes for VCard output
#include "windows.h"
#include "JetBTConfig.h"

#define SZ_EMPTY _T("")
#define SZ_ENCODE_UTF8 _T(";ENCODING=UTF-8")
#define SZ_ENCODE_UCS2 _T(";ENCODING=UCS2")
#define CHARSET_GSM		0
#define CHARSET_UTF8	1
#define CHARSET_UCS2	2
#define CHARSET_7BIT	3
#define CHARSET_8BIT	4

enum NAME_FORMAT
{
	FILE_AS = 0,
	LAST_COMMA_FIRST,
	LAST_COMMA_FI,
	LAST_FIRST,
	LAST_FI,
	FIRST_LAST,
	FI_LAST,
	FIRST_LI
};

typedef struct tagPTR_LIST
{
    void        * Item;
    tagPTR_LIST * Next;
} PTR_LIST, FAR * LPPTR_LIST;

enum ADDR_TYPE
{
    ADDR_HOME = 0,
    ADDR_WORK,
    ADDR_OTHER
};
// CAddress provides storage for home or business address
class CAddress
{
public:
    CAddress(ADDR_TYPE Type);
    ~CAddress();
    DWORD WriteToStream(HANDLE hStream);
    void SetStreet(TCHAR * szStreet);
    void SetCity(TCHAR * szCity);
    void SetState(TCHAR * szState);
    void SetZip(TCHAR * szZip);
    void SetCountry(TCHAR * szCountry);
private:
    TCHAR * m_szStreet;
    TCHAR * m_szCity;
    TCHAR * m_szState;
    TCHAR * m_szZip;
    TCHAR * m_szCountry;
    // TCHAR m_szEmpty[2];
    // Store lengths when setting strings so we don't have to calc string lens again
    WORD m_wStreetLen;
    WORD m_wCityLen;
    WORD m_wStateLen;
    WORD m_wZipLen;
    WORD m_wCountryLen;
    ADDR_TYPE m_Type;
};

#define SZ_PREF     "PREF"
#define SZ_VOICE    "VOICE"
#define SZ_FAX      "FAX"
#define SZ_HOME     "HOME"
#define SZ_WORK     "WORK"
#define SZ_CELL     "CELL"
#define SZ_CAR      "CAR"
#define SZ_PAGER    "PAGER"

enum NUM_TYPE
{
    NUM_HOME = 0,   // "PREF;HOME;VOICE"    - 15
    NUM_MOBILE,     // "CELL;VOICE"         - 10
    NUM_WORK,       // "PREF;WORK;VOICE"    - 15
    NUM_CAR,        // "CAR;VOICE"          - 9
    NUM_ASST,       // "WORK;VOICE"         - 10
    NUM_WORK2,      // "WORK;VOICE"         - 10
    NUM_HOME2,      // "HOME;VOICE"         - 10
    NUM_PAGER,      // "PAGER"              - 5
    NUM_RADIO,      // "VOICE"              - 5
    NUM_FAX_WORK,   // "WORK;FAX"           - 8
    NUM_FAX_HOME,   // "HOME;FAX"           - 8
	NUM_TYPE_MAX
};

// CPhone provides storage for a phone number
class CPhone
{
public:
    CPhone(TCHAR * szNumber, NUM_TYPE Type);
    ~CPhone();
    DWORD WriteToStream(HANDLE hStream);
private:
    TCHAR * m_szNumber;
    WORD m_wNumLen;
    NUM_TYPE m_Type;
};

class CContact
{
public:
    CContact();
    ~CContact();
    DWORD WriteToStream(HANDLE hStream);
    void AddAddress(CAddress * Address);
    void AddPhone(CPhone * Phone);
    void SetFirstName(TCHAR * Name);
    void SetLastName(TCHAR * Name);
    void SetFileAs(TCHAR * Name);
    void SetEmail(TCHAR * Email);
	void SetNumbersPerVCard(DWORD dwCount) { m_dwNumbersPerCard = dwCount; };
	void SetMaxNumbersPerContact(DWORD dwCount) { m_dwNumbersPerContact = dwCount; };
	void SetFnFormat(DWORD dwFormat, DWORD dwMaxLen = 0) { m_dwFNFormat = dwFormat; m_dwMaxNameLen = dwMaxLen; };
	void SetEncoding(DWORD dwEncode) { m_dwEncode = dwEncode; };
private:
    LPPTR_LIST m_PhoneList;
    LPPTR_LIST m_AddrList;
    TCHAR * m_szFirstName;
    TCHAR * m_szLastName;
    TCHAR * m_szFileAs;
    TCHAR * m_szEmail;
    WORD    m_wFirstNameLen;
    WORD    m_wLastNameLen;
    WORD    m_wFileAsLen;
    WORD    m_wEmailLen;
    DWORD   WritePrefix(HANDLE hStream);
	void	FormatName();
    DWORD   WriteNameProps(HANDLE hStream);
    DWORD   WriteTelProps(HANDLE hStream, int * pStartIndex, int * pCount);
    DWORD   WriteAdrProps(HANDLE hStream);
    DWORD   WriteEmailProps(HANDLE hStream);
    DWORD   WriteSuffix(HANDLE hStream);
	// User Settings
	DWORD	m_dwNumbersPerCard;
	DWORD	m_dwNumbersPerContact;
	DWORD	m_dwFNFormat;
	DWORD	m_dwMaxNameLen;
	DWORD	m_dwEncode;
};